-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Joints
implementation
#150
base: main
Are you sure you want to change the base?
Conversation
Hi @alvarosabu, I just added a base documentation for cc: @JaimeTorrealba |
- Init joint component - Add `JointProps` interface - Add Joint Demo
683f466
to
8c4afea
Compare
Any update on this one?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the implementation, But also I would add a composable WDYT? With the same logic
an useJoint()
or similar so the people is not force to use it with Tres.js components only
docs/components/joint.md
Outdated
|
||
Joints is an extension feature provided in [Rapier#Joint](https://rapier.rs/docs/user_guides/javascript/joints/). It lets us connect two or more bodies, restricting their movements according to each other. | ||
|
||
In **Tres** we can achieve such motion restriction by using one of the available components designed to handle joints: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small one but maybe we need consistency here it all pages should be "Tres.js"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted
docs/components/joint.md
Outdated
|
||
<template> | ||
<RigidBody | ||
v-for="(ref, i) in bodyRefs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got a problem, the mental load of this example is high. I would instead, in this page, come with a very basic example, just two rigid Bodies joined (just that). The idea here is that they learn how to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example reflects the one in the playground (the JointsDemo
example)...
Is it okay to simplify this one in this documentation but keep the demo as it is?
Array.from({ length: 10 }).map(() => shallowRef<ExposedRigidBody>(null)), | ||
) | ||
|
||
setInterval(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why setInterval?
And if you decided to use setInterval, please remember to clear the interval in the onUnmouted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, you're right,
setInterval
was used to update the rotation of the first and have that whip effect
src/components/joints/BaseJoint.vue
Outdated
} | ||
|
||
if (hasParamsError) { | ||
throw new Error(`Invalid "${type}" joint parameters`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe too difficult, but could be said what parameters have problems?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, maybe a string containing the requirement or why it the error occurs
I think it possible even to have both features |
Completely, maybe another PR to be more organized. |
### Description - Make the Joint component listen to updates - Provide more precise `Joint` error messages - Simplify the Joint example and the Joint documentation - Remove `cSpell.words` VsCode setting
I pushed the changes requested, and yes, this will be part of a separate PR ✅ Here what has changed:
|
|
||
```vue | ||
<script setup lang="ts"> | ||
<script setup> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Neosoulink examples should be in Typescript as much as possible:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Neosoulink you need to add the entry on docs/.vitepress/config
so it's available on the side navigation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted
]" | ||
/> | ||
</template> | ||
``` | ||
|
||
> Preview | ||
<img width="843" alt="Screenshot 2024-12-09 at 4 01 58PM" src="https://github.com/user-attachments/assets/9baaea58-f996-45d5-b4f4-34dae30d44cb"> | ||
<img width="1141" alt="JointsDemo" src="https://github.com/user-attachments/assets/d3cacac3-8764-4906-886a-d0b7a764b7c0" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Neosoulink Why not using the normal markdown image notation for this?
![JointsDemo](https://github.com/user-attachments/assets/d3cacac3-8764-4906-886a-d0b7a764b7c0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was automatically added from github, but let make it clean. I'm going to update it
### Explanation | ||
|
||
In the above example, we created a list of 10 `RigidBody` references and mapped them using the `v-for` directive. Then, we implemented the `SphericalJoint` component, creating a Joint between each mapped `RigidBody`. | ||
In the above example, we created 2 `RigidBody` references, then, we implemented the `SphericalJoint` component, by placing our 2 `RigidBody` references in the `:bodies` property and specifying parameters, we created a `spherical-joint` between them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we created two RigidBody
references
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Neosoulink if I understand correctly the scope of this file is to generate several components using BaseJoint.vue
as a base, but why? Why not just directly create the SFC components per kind of joint? They are only 7
This is an unusual pattern for vue that we don't use anywhere else in the ecosystem, I will strongly suggest we just separate this into different Joint components.
You could even just have one Join
component and pass a prop defining the type and having <component :is="AnyJointComponent" />
under the hood.
Let me know if I can support you with this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach prioritizes re-usability based on the same component.
In other words, it's just a shortcut for the Joints
It's exactly the same as doing:
<Joint type="joint-type" />
What makes it efficient (in my point of view) is that there is only one source of truth, one part dealing with the main feature and other parts extending from it.
Plus, the child components can have props type precisions and be aware of what the parent needs for the props
I often used to implement a few years ago, back in 2019 (old goods days 🥲)
It's a pattern I discovered while learning howVue
was working under the hood
Summary
This PR introduces the Joints feature.
Joints are one of the advanced features natively available in
Rapier
.This PR provides an easy, basic but robust way to deal with it.
Logs
"fixed" | "spring" | "rope" | "generic" | "spherical" | "prismatic" | "revolute"
FixedJoint
,SphericalJoint
, ...)How to use
Here's a basic implementation example:
Screen.Recording.2024-11-20.at.2.10.27.AM.mov